package com.ruoyi.orderEat.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.orderEat.domain.ShopSkuInfoVO;
import com.ruoyi.orderEat.web.SaleStateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.orderEat.mapper.ShopSkuInfoMapper;
import com.ruoyi.orderEat.domain.ShopSkuInfo;
import com.ruoyi.orderEat.service.IShopSkuInfoService;

/**
 * 商品规格Service业务层处理
 * 
 * @author DingHao
 * @date 2023-11-24
 */
@Service
public class ShopSkuInfoServiceImpl implements IShopSkuInfoService 
{
    @Autowired
    private ShopSkuInfoMapper shopSkuInfoMapper;

    /**
     * 查询商品规格
     * 
     * @param shopSkuId 商品规格主键
     * @return 商品规格
     */
    @Override
    public ShopSkuInfo selectShopSkuInfoByShopSkuId(Long shopSkuId)
    {
        return shopSkuInfoMapper.selectShopSkuInfoByShopSkuId(shopSkuId);
    }

    /**
     * 查询商品规格列表
     *
     * @param shopSkuInfo 商品规格
     * @return 商品规格
     */
    @Override
    public List<ShopSkuInfoVO> selectShopSkuInfoList(ShopSkuInfo shopSkuInfo)
    {
        List<ShopSkuInfoVO> shopSkuInfoVOS = shopSkuInfoMapper.selectShopSkuInfoList(shopSkuInfo);
        shopSkuInfoVOS.stream().forEach(item->{
            String statusName = SaleStateCode.getDesc(Integer.parseInt(item.getShopSkuStatus()));
            item.setShopSkuStatusName(statusName);
        });
        return shopSkuInfoVOS;
    }

    @Override
    public List<ShopSkuInfoVO> selectShopSkuInfoVOList(ShopSkuInfo shopSkuInfo) {


        return null;
    }

    /**
     * 新增商品规格
     * 
     * @param shopSkuInfo 商品规格
     * @return 结果
     */
    @Override
    public int insertShopSkuInfo(ShopSkuInfo shopSkuInfo)
    {
        Long userId = SecurityUtils.getUserId();
        shopSkuInfo.setCreateBy(String.valueOf(userId));
        shopSkuInfo.setCreateTime(DateUtils.getNowDate());
        return shopSkuInfoMapper.insertShopSkuInfo(shopSkuInfo);
    }

    /**
     * 修改商品规格
     * 
     * @param shopSkuInfo 商品规格
     * @return 结果
     */
    @Override
    public int updateShopSkuInfo(ShopSkuInfo shopSkuInfo)
    {
        Long userId = SecurityUtils.getUserId();
        shopSkuInfo.setUpdateBy(String.valueOf(userId));
        shopSkuInfo.setUpdateTime(DateUtils.getNowDate());
        return shopSkuInfoMapper.updateShopSkuInfo(shopSkuInfo);
    }

    /**
     * 批量删除商品规格
     * 
     * @param shopSkuIds 需要删除的商品规格主键
     * @return 结果
     */
    @Override
    public int deleteShopSkuInfoByShopSkuIds(Long[] shopSkuIds)
    {
        return shopSkuInfoMapper.deleteShopSkuInfoByShopSkuIds(shopSkuIds);
    }

    /**
     * 删除商品规格信息
     * 
     * @param shopSkuId 商品规格主键
     * @return 结果
     */
    @Override
    public int deleteShopSkuInfoByShopSkuId(Long shopSkuId)
    {
        return shopSkuInfoMapper.deleteShopSkuInfoByShopSkuId(shopSkuId);
    }
}
